import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/26 19:43
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.minimumLength("aabccabba"));
    }

    public int minimumLength(String s) {
        int n = s.length(), l = 0, r = n - 1;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                break;
            }
            while (l + 1 < r && s.charAt(l + 1) == s.charAt(l)) {
                l++;
            }
            while (r - 1 > l && s.charAt(r - 1) == s.charAt(r)) {
                r--;
            }
            l++;
            r--;
        }
        return r - l + 1;
    }
}
